package com.adtech.farmProducts.adapter;

import android.support.v4.content.ContextCompat;
import android.support.v7.widget.AppCompatImageView;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.adtech.common.widgets.recycler.RecyclerViewAdapter;
import com.adtech.farmProducts.R;
import com.adtech.farmProducts.model.CommodityType;


/**
 * Author:  xiaocz.
 * Descr:  产品分类
 */
public class CommodityTypeAdapter extends RecyclerViewAdapter<CommodityType> {

    public CommodityTypeAdapter(AdapterListener<CommodityType> adapterListener) {
        super(adapterListener);
    }

    @Override
    protected int getItemViewType(int position, CommodityType data) {
        return R.layout.item_commodity_type;
    }

    @Override
    protected ViewHolder<CommodityType> getViewHolder(View view, int viewType) {
        return new InfoTypeViewHolder(view);
    }

    private static class InfoTypeViewHolder extends ViewHolder<CommodityType> {

        private LinearLayout layout_base;
        private TextView tvName;
        private AppCompatImageView iv_view;

        private InfoTypeViewHolder(View itemView) {
            super(itemView);
            layout_base=itemView.findViewById(R.id.layout_base);
            tvName = itemView.findViewById(R.id.tv_name);
            iv_view=itemView.findViewById(R.id.iv_view);
        }

        @Override
        protected void onBind(CommodityType data, int position) {
            tvName.setText(data.getProductItemName());
            if(data.isCheck()){
                tvName.setTextColor(
                        ContextCompat.getColor(mContext,R.color.colorPrimary));
                iv_view.setVisibility(View.VISIBLE);
                layout_base.setBackgroundColor( ContextCompat.getColor(mContext,R.color.white));
            }else {
                tvName.setTextColor(
                        ContextCompat.getColor(mContext,R.color.textColorFirst));
                iv_view.setVisibility(View.GONE);
                layout_base.setBackgroundColor( ContextCompat.getColor(mContext,R.color.windowsBackground));
            }
        }

        @Override
        public boolean isNeedClick() {
            return true;
        }
    }
}